package com_.dxy_.test_.transaction_;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description 事务测试接口
 * @Author dangxianyue
 * @Date 2022/10/13 10:05
 */
@RestController
@RequestMapping("/transaction")
public class TransactionTestController {

    @Autowired
    private TransactionTestService transactionTestService;

    //测试声明式事务
    @GetMapping("testDeclareTransaction")
    public Object testDeclareTransaction() throws Exception {
        //return transactionTestService.saveUserV1();//类内调用，无效
        return transactionTestService.saveUserV2();//类外调用，生效
    }

    //测试编程式事务
    @GetMapping("testCodingTransaction")
    public Object testCodingTransaction() throws Exception {
        //return transactionTestService.saveUserV1();//类内调用，生效
        //return transactionTestService.saveUserV3();//类外调用，生效
        return transactionTestService.saveUserV4();//测试检查型异常如何处理
    }
}
